# this script prompts the user to enter the name of a cell config file and how long to run a simulation.
#    then the script runs the simulation and outputs the cell as a cPickle.
from Prinz_classes import *
import os
from Prinz_functions import *

# prompt user to pick a configuration file
config = pick_config()

# find out if the cell has a previous simulation run
found_previous = False
listing = os.listdir('.')
for file in listing:
    if config[1] == file:
        c = Ccell.from_data_file( file+'/cell_data.cPickle')
        found_previous = True
        print "We've found that this cell has been simulated previously for %d ms." % (c.total_time)

# ------------- run a novel simulation -----------------------
if not found_previous:
    
    sim_time = int(raw_input("How long would you like to simuate?    "))
    confirmation = raw_input("You will be simulating %s for %d ms.  Is this ok? [y]/n     "%(config[0],sim_time))
    while "n" in confirmation:
        sim_time = int(raw_input("How long would you like to simuate?    "))
        confirmation = raw_input("You will be simulating %s for %d ms.  Is this ok? [y]/n     "%(config[0],sim_time))
    
    # run the simulation for some time
    c.exercise(i_time = sim_time)

    # archive the resulting cell
    c.archive(config[1])
else:
    #-------------- run more simulation time -----------------------
    # create the cell object from the data file
    c = Ccell.from_data_file(config[1] + '/cell_data.cPickle')

    sim_time = int(raw_input("How long would you like to simuate?    "))
    confirmation = raw_input("You will be simulating %s for an additional %d  ms (new total_time = %d).  Is this ok? [y]/n     "%(config[0],sim_time,c.total_time+sim_time))
    while "n" in confirmation:
        sim_time = int(raw_input("How long would you like to simuate?    "))
        confirmation = raw_input("You will be simulating %s for an additional %d  ms (new total_time = %d).  Is this ok? [y]/n     "%(config[0],sim_time,c.total_time+sim_time))

    # run the simulation for some time
    c.exercise(i_time = sim_time,X_init = c.X[-1])

    # archive the resulting cell
    c.archive(config[1])



    

